use actix_web::HttpResponse;

use common::error::MyError;
use common::r::JsonResult;
use entity::resource;
use model::resource::{CreateResource, ResourcePage};
use service::manager::resource::ResourceManager;
use service::resource::ResourceService;

use crate::controller::base::BaseController;

pub struct ResourceController {}

impl
    BaseController<
        ResourceService,
        i64,
        resource::Model,
        ResourcePage,
        CreateResource,
        resource::Model,
        ResourceManager,
    > for ResourceController
{
}

impl ResourceController {
    pub async fn resource_tree() -> Result<HttpResponse, MyError> {
        let resource_tree = ResourceService::resource_tree().await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(resource_tree)))
    }
}
